//
//  ILLinkObject.h
//  IMILabKit
//
//  Created by Roffa Zhou on 2022/5/30.
//

#import <Foundation/Foundation.h>
#import "ILLinkPeripheral.h"
#import "ILLinkDefine.h"
#import "ILLinkStateModel.h"
#import "ILLinkErrorModel.h"

#if defined(__has_include) && __has_include(<IMILabSDK_Log/ILLog.h>)
#import <IMILabSDK_BindCommon/ILBindDefine.h>

#else
#import "ILBindDefine.h"


#endif

typedef void(^ILLinkObjectQRBlock)(NSDictionary * _Nullable result);

NS_ASSUME_NONNULL_BEGIN

@interface ILLinkObject : NSObject

/// 当前正在绑定的外设
@property(nonatomic, strong)ILLinkPeripheral *peripheral;

/// 当前状态
@property(nonatomic, strong)ILLinkStateModel *stateModel;

/// 当前错误
@property(nonatomic, strong)ILLinkErrorModel *errorModel;

//绑定流程最后一步的绑定接口调用已成功。可最为最终完成回调或者通过监听状态
@property(nonatomic, copy)IL_Bind_Link_Succ_Block __nullable bindSuccessBlock;

//绑定错误更新回调
@property(nonatomic, copy)IL_Bind_Link_Error_Block _Nullable bindErrorBlock;

//绑定状态更新回调
@property(nonatomic, copy)IL_Bind_Link_Mode_Block _Nullable  bindStateBlock;

/// 重试block,内部使用
@property(nonatomic, copy, nullable)ILBindRetryBlock retryBlock;

/// 初始化方法
/// @param peripheral <#peripheral description#>
+ (instancetype)initWithPeripheral:(ILLinkPeripheral *)peripheral;

/// 连接设备
- (void)linkDevice;

/// 停止连接
- (void)stopLink;

/// 更新错误
/// @param code <#code description#>
/// @param subCode <#subCode description#>
/// @param canRetry <#canRetry description#>
- (void)updateLinkError:(ILBindError)code subCode:(NSInteger)subCode canRetry:(BOOL)canRetry;

/// 更新当前状态
/// @param mode <#mode description#>
/// @param subCode <#subCode description#>
- (void)updateBindMode:(ILLinkState)mode subCode:(NSInteger)subCode;

/// 从错误处重试绑定
- (void)retryBind;

/// 获取二维码绑定时需要展示的二维码内容(QR绑定时,必须先展示内容,等待设备完成扫描流程后,再调用linkDevice)
/// pwd当前连接的wifi的密码
/// complet @{@"qrConent":@"xxx", @"token":@"xxx"}
+ (void)getQRCodeContentWithWifiPwd:(NSString *)pwd complet:(ILLinkObjectQRBlock)complet;

@end

NS_ASSUME_NONNULL_END
